#ifndef __APP_SERIAL_H__
#define __APP_SERIAL_H__

#include "app_device.h"
#include <termios.h>

typedef enum BaudrateEnum
{
    BAUD_9600 = B9600,
    BAUD_19200 = B19200,
    BAUD_38400 = B38400,
    BAUD_57600 = B57600,
    BAUD_115200 = B115200
} Baudrate;

typedef enum DataBitsEnum
{
    DATA_BITS_5 = CS5,
    DATA_BITS_6 = CS6,
    DATA_BITS_7 = CS7,
    DATA_BITS_8 = CS8
} DataBits;

typedef enum StopBitsEnum
{
    STOP_BITS_1 = 0,
    STOP_BITS_2 = CSTOPB
} StopBits;

typedef enum ParityEnum
{
    PARITY_NONE = 0,
    PARITY_ODD = PARENB | PARODD,
    PARITY_EVEN = PARENB,
} Parity;

typedef struct SerialDeviceObj
{
    Device super;
    Baudrate baudrate;
    DataBits data_bits;
    StopBits stop_bits;
    Parity parity;
} SerialDevice;

SerialDevice *app_serial_init(char *dev_name);

int app_serial_setBaudrate(SerialDevice *dev, Baudrate baudrate);
int app_serial_setDataBits(SerialDevice *dev, DataBits data_bits);
int app_serial_setStopBits(SerialDevice *dev, StopBits stop_bits);
int app_serial_setParity(SerialDevice *dev, Parity parity);

int app_serial_setConnectionType(SerialDevice *dev, ConnectionType type);

#endif /* __APP_SERIAL_H__ */